home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-23 | 2.8 KB | 175 lines | [TEXT/MSET] |
- \ The class Bytestring adds further methods to the class String+.
- \ These methods allow various numbers of bytes to be fetched from
- \ or stored to the current position of the bytestring, with the
- \ current position being updated. Any data can be stored in these bytes -
- \ not necessarily Ascii characters.
-
- :class BYTESTRING super{ string+ }
-
- :mcode 1STW: \ ( -- n )
- loc
- BSR dic[getit]
- SUBQ #2,D0
- BGE.S ok
- JMP dic[$fail]
- ok MOVEQ #0,D1
- MOVE.W (A0),D1
- PUSH D1
- ;mcode
-
- :mcode 1STL: \ ( -- n )
- loc
- BSR dic[getit]
- SUBQ #4,D0
- BGE.S ok
- JMP dic[$fail]
- ok MOVEQ #0,D1
- MOVE (A0),D1
- PUSH D1
- ;mcode
-
- :mcode >1ST: \ ( c -- )
- loc
- BSR dic[getit]
- BNE.S ok
- JMP dic[$fail]
- ok POP D1
- MOVE.B D1,(A0)
- ;mcode
-
- :mcode >1STW: \ ( w -- )
- loc
- BSR dic[getit]
- SUBQ #2,D0
- BGE.S ok
- JMP dic[$fail]
- ok POP D1
- MOVE.W D1,(A0)
- ;mcode
-
- :mcode >1STL: \ ( w -- )
- loc
- BSR dic[getit]
- SUBQ #4,D0
- BGE.S ok
- JMP dic[$fail]
- ok POP D1
- MOVE D1,(A0)
- ;mcode
-
- :mcode OFFSC: \ ( n -- c )
- BSR dic[getit]
- MOVEQ #0,D1
- ADD (SP),A0
- MOVE.B (A0),D1
- MOVE D1,(SP)
- ;mcode
-
- :mcode >OFFSC: \ ( c n -- )
- BSR dic[getit]
- ADD (SP)+,A0
- POP D1
- MOVE.B D1,(A0)
- ;mcode
-
-
- :mcode NXTC: \ ( -- c )
- loc
- BSR dic[getit]
- BNE.S ok
- JMP dic[$fail]
- ok MOVEQ #0,D1
- MOVE.B (A0),D1
- ADDQ #1,8(A2)
- PUSH D1
- ;mcode
-
- :m NXTW:
- 1stW: self 2 skip: self ;m
-
- :m NXTL:
- 1stL: self 4 skip: self ;m
-
- :m NXTN: { n -- n' }
- get: self n >=
- IF 0 swap n bounds DO 8 << i c@ or LOOP
- n skip: self
- ELSE drop 0
- THEN ;m
-
-
- :m >NXTC: \ ( c -- )
- >1st: self 1 skip: self ;m
-
- :m >NXTW: \ ( n -- )
- >1stW: self 2 skip: self ;m
-
- :m >NXTL:
- >1stL: self 4 skip: self ;m
-
- :m >NXT$: \ ( addr len -- )
- ovwr: self ;m
-
- :m >NXTN: { val n -- }
- val pad !
- 4 n - pad + n >nxt$: self ;m
-
-
- :m +C: \ ( c -- )
- +: self ;m
-
- :m +W: \ ( n -- )
- pad w! pad 2 add: self ;m
-
- :m +L: \ ( n -- )
- pad ! pad 4 add: self ;m
-
- :m +N: { n cnt -- }
- n 32 cnt 2* 4* - << pad !
- pad cnt add: self ;m
-
-
- :mcode COUNT: \ Assumes the substring starting at POS is a
- \ counted string, and sets POS and LIM to delimit it.
- \ Note: ignores the initial value of LIM, which
- \ hardly matters anyway. (It was easy to forget to do
- \ NOLIM:, until I changed this.)
-
- MOVE 4(A2),12(A2) ; nolim: self
- BSR dic[getit]
- MOVEQ #0,D0
- MOVE.B (A0),D0
- ADDQ #1,8(A2)
- ADD 8(A2),D0
- MOVE D0,12(A2)
- ;mcode
-
- :mcode WCOUNT: \ As for COUNT:, but with a 2-byte length, maybe non-aligned.
-
- MOVE dic[big#],12(A2) ; Set LIM to a big number
- BSR dic[getit]
- MOVEQ #0,D0
- MOVE.B (A0),D0
- LSL.W #8,D0
- MOVE.B 1(A0),D0
- ADDQ #2,8(A2)
- ADD 8(A2),D0
- MOVE D0,12(A2)
- ;mcode
-
- ;class
-
- :code 2B@ \ ( addr -- n ) 2-byte fetch, non-aligned.
- MOVE (SP),A0
- CLR (SP)
- MOVE.B (A0)+,2(SP)
- MOVE.B (A0),3(SP)
- ;code
-
- :code 2B! \ ( addr n -- ) 2-byte store.
- MOVE (SP)+,A0
- MOVE.B 2(SP),(A0)+
- MOVE.B 3(SP),(A0)+
- ADDQ #4,SP
- ;code
-